//
//  MyViewController.m
//  Wy_BuyBooks
//
//  Created by wangyang on 2020/2/6.
//  Copyright © 2020 wangyang. All rights reserved.
//

#import "MyViewController.h"
#import "CollectionVc.h"
#import "PoliteVc.h"
#import "AboutVc.h"
#import "FeedbackVc.h"
#import "WyLnadViewController.h"
@interface MyViewController ()
@property (nonatomic,strong) UIScrollView   *WyScrollView;

@end

@implementation MyViewController
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES animated:animated];
    if ([WyEngineering sharedUser].login == YES) {

          [self WyScrollView];
        [self initSetUI];

       }else{

           //                [self.MyTableView removeFromSuperview];
           //                self.MyTableView = nil;
           WyLnadViewController *VC = [[WyLnadViewController alloc] init];
           VC.LandVcBlock = ^{
               //                        [self.MyTableView removeFromSuperview];
               //                        self.MyTableView = nil;
               self.tabBarController.selectedIndex = 0;
           };
           [self.navigationController pushViewController:VC animated:YES];
       }
}
-(void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [self WyScrollView];
    if (@available(iOS 11.0, *)) {
        
        self.WyScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
//    [self initSetUI];
}

-(void)initSetUI{
    
    
    
    NSArray * arrayImg = @[@"我的收藏",@"我的优惠券",@"联系我们",@"意见反馈",@"关于我们",@"退出登录"];
    NSArray * arrayLab = @[@"我的收藏",@"我的优惠券",@"联系我们",@"意见反馈",@"关于我们",@"退出登录"];
       
       for (int i = 0; i<arrayImg.count; i++) {
           UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
           [self.BackImg addSubview:btn];
           btn.tag = i;
           [btn setTitle:arrayLab[i] forState:0];
           [btn setFont:WySYSTEMFONT(12)];
           [btn setImage:[UIImage imageNamed:arrayImg[i]] forState:0];
           [btn setImageEdgeInsets:UIEdgeInsetsMake(-btn.titleLabel.intrinsicContentSize.height, 0, 0, -btn.titleLabel.intrinsicContentSize.width)];
           [btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.currentImage.size.height+20, -btn.currentImage.size.width, 0, 0)];
           [btn setTitleColor:[UIColor blackColor] forState:0];
           [btn addTarget:self action:@selector(selector:) forControlEvents:UIControlEventTouchUpInside];
           [btn mas_makeConstraints:^(MASConstraintMaker *make) {
               make.size.equalTo(CGSizeMake(BiLiWidth(70), BiLiWidth(60)));
               make.top.mas_offset(BiLiWidth(10)+(BiLiWidth(80))*(i/3));
               make.left.mas_offset(BiLiWidth(30)+(120)*(i%3));
           }];
           
           
       }
    
}

-(void)selector:(UIButton *)button
{
    if (button.tag == 0) {
        [self.navigationController pushViewController:[CollectionVc alloc] animated:YES];
    }
    else if (button.tag == 1)
    {
         [self.navigationController pushViewController:[PoliteVc alloc] animated:YES];
    }
    else if (button.tag == 2)
    {
         [[AlertControllerCustom shareInstance] showAlert:@"请拨打官方服务热线\n0371-66666" viewController:self];
    }
    else if (button.tag == 3)
    {
        [self.navigationController pushViewController:[FeedbackVc alloc] animated:YES];
    }
    else if (button.tag == 4)
    {
        [self.navigationController pushViewController:[AboutVc alloc] animated:YES];
    }
    else if (button.tag == 5)
    {
        
    }
}


- (UIScrollView *)WyScrollView {
    
    if (!_WyScrollView) {
        _WyScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:_WyScrollView];
        _WyScrollView.userInteractionEnabled = YES;
        _WyScrollView.showsVerticalScrollIndicator = NO;
        _WyScrollView.contentSize = CGSizeMake(WySCREENWIDTH, WySCREENHEIGHT*1);
        _WyScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_WyScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_offset(0);
            
        }];
        [self TopImg];
        [self BackImg];
       
    }
    return _WyScrollView;
}

- (UIImageView *)TopImg

{
    if (!_TopImg) {
        
        _TopImg = [UIImageView imageWithImgName:@"矩形" superView:self.WyScrollView];
        _TopImg.userInteractionEnabled = YES;
        [_TopImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH, BiLiWidth(200)));
            make.centerX.mas_offset(0);
            make.top.mas_offset(0);
        }];
        [self HeadImg];
        [self NameLabe];
    }
    return _TopImg;
}
- (UIImageView *)BackImg

{
    if (!_BackImg) {
        
        _BackImg = [UIImageView imageWithImgName:@"grid" superView:self.WyScrollView];
        _BackImg.userInteractionEnabled = YES;
        [_BackImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(28), BiLiWidth(157)));
            make.centerX.mas_offset(0);
            make.top.equalTo(self.TopImg.bottom).offset(BiLiWidth(50));
        }];
    }
    return _BackImg;
}

- (UIImageView *)HeadImg

{
    if (!_HeadImg) {
        
        _HeadImg = [UIImageView imageWithImgName:@"头像" superView:self.TopImg];
        [_HeadImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(60), BiLiWidth(60)));
            make.left.mas_offset(BiLiWidth(20));
            make.top.mas_offset(BiLiWidth(86));
        }];
        
    }
    return _HeadImg;
}

- (UILabel *)NameLabe

{
    if (!_NameLabe) {
        
        
        _NameLabe = [UILabel labelWithContent:@"敢笑陆羽不懂茶" superView:self.TopImg textColor:WyWhiteColor font:[UIFont systemFontOfSize:14] textAlignment:NSTextAlignmentCenter];
        [_NameLabe mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(100), BiLiWidth(20)));
            make.top.mas_offset(BiLiWidth(106));
            make.left.equalTo(self.HeadImg.right).offset(BiLiWidth(8));
        }];
        
    }
    
    return _NameLabe;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
